/*
 * All header file for c language MUST be include : in extern "C" { }
 */
extern "C" {
#include "../src/uni_config.c"
}

#define CONFIG_NAME  "config_file_for_test"

H2UNIT(config) {
  void setup() {
    ConfigInitialize();
    system("cp config_file_for_test config_file_for_test_bak");
  }
  void teardown() {
    system("mv config_file_for_test_bak config_file_for_test");
    ConfigFinalize();
  }
};

H2CASE(config, "ConfigReadItemNumber") {
  int ret;
  uni_s64 number;
  ret = ConfigReadItemNumber(CONFIG_NAME, "rasr.protocol", &number);
  H2EQ_MATH(0, ret);
  H2EQ_MATH(1, number);
  ret = ConfigReadItemNumber(CONFIG_NAME, "rasr.protocol1", &number);
  H2EQ_MATH(-1, ret);
}

H2CASE(config, "ConfigReadItemDouble") {
  int ret;
  double number;
  ret = ConfigReadItemDouble(CONFIG_NAME, "lasr.lasr_wkp.eng.std_threshold", &number);
  H2EQ_MATH(0, ret);
  H2EQ_MATH(-4.2, number);
  ret = ConfigReadItemDouble(CONFIG_NAME, "lasr.lasr_wkp.eng.std_threshold1", &number);
  H2EQ_MATH(-1, ret);
}

H2CASE(config, "ConfigReadItemString") {
  int ret;
  char buf[128] = {0};
  ret = ConfigReadItemString(CONFIG_NAME, "rasr.ser.appkey", buf, sizeof(buf));
  H2EQ_MATH(0, ret);
  H2EQ_STRCMP("i436ztt5vg7hvwftoei6fjd6n7m2ahdrk7htjjal", buf);
  ret = ConfigReadItemString(CONFIG_NAME, "rasr.ser.appkey1", buf, sizeof(buf));
  H2EQ_MATH(-1, ret);
}

H2CASE(config, "ConfigWriteItemNumber") {
  int ret;
  uni_s64 number;
  ret = ConfigWriteItemNumber(CONFIG_NAME, "lasr.lasr_wkp.eng.mode", 10);
  H2EQ_MATH(0, ret);
  ret = ConfigReadItemNumber(CONFIG_NAME, "lasr.lasr_wkp.eng.mode", &number);
  H2EQ_MATH(10, number);
  ret = ConfigWriteItemNumber(CONFIG_NAME, "lasr.lasr_wkp.eng.mode1", 10);
  H2EQ_MATH(-1, ret);
}

H2CASE(config, "ConfigWriteItemDouble") {
  int ret;
  double number;
  ret = ConfigWriteItemDouble(CONFIG_NAME, "lasr.lasr_asr.eng.std_threshold", 0.1);
  H2EQ_MATH(0, ret);
  ret = ConfigReadItemDouble(CONFIG_NAME, "lasr.lasr_asr.eng.std_threshold", &number);
  H2EQ_MATH(0.1, number);
  ret = ConfigWriteItemDouble(CONFIG_NAME, "lasr.lasr_asr.eng.std_threshold1", 0.1);
  H2EQ_MATH(-1, ret);
}

H2CASE(config, "ConfigWriteItemString") {
  int ret;
  char buf[128] = {0};
  ret = ConfigWriteItemString(CONFIG_NAME, "name", "hello world");
  H2EQ_MATH(0, ret);
  ret = ConfigReadItemString(CONFIG_NAME, "name", buf, sizeof(buf));
  H2EQ_STRCMP("hello world", buf);
  ret = ConfigWriteItemString(CONFIG_NAME, "name1", "hello world");
  H2EQ_MATH(-1, ret);
}
